package de.g18.scavengerhunt.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.KeyEvent;
import android.widget.TextView;
import de.g18.scavengerhunt.AppApplicationContext;
import de.g18.scavengerhunt.R;
import de.g18.scavengerhunt.utils.GameUtils;

/**
 * This is the activity for showing the rules
 */
public class RulesActivity extends Activity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rules);
        
        TextView txtRules = (TextView) findViewById(R.id.txtRules);
        txtRules.setText(Html.fromHtml(getString(R.string.rulesText)));
        txtRules.setMovementMethod(new ScrollingMovementMethod());
    }
    
    /**
     * Called automatically when the Activity has been created and will be visible to the user.
     */
    @Override
    protected void onStart() {
    	super.onStart();
    	
    	// Give the ApplicationContext the current activity instance.
    	AppApplicationContext.setActivity(this);
    }
    
    /**
     * This override makes sure, that the device back button only intents to load the MainMenuActivity.
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        	GameUtils.showActivity(new MainMenuActivity());
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }
}